package com.gagakuai.util;


import com.gagakuai.base.vo.Result;
import com.gagakuai.enumeration.BusinessCodeEnum;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.http.HttpStatus;

/*
 * @program: mss_server
 * @description: 结果工具类
 * @author: houhong
 * @create: 2021-12-10 14:21
 */
public class ResultUtils {


    public static <T> Result<T> success(T data, BusinessCodeEnum businessCodeEnum) {

        Result<T> result = new Result<T>();

        result.setSuccess(true);
        result.setMessage(businessCodeEnum.getDescription());
        result.setCode(HttpStatus.OK.value());

        result.setResult(data);

        return result;
    }

    public static <T> Result<T> success(BusinessCodeEnum businessCodeEnum) {

        Result<T> result = new Result<T>();

        result.setSuccess(true);
        result.setMessage(businessCodeEnum.getDescription());
        result.setCode(HttpStatus.OK.value());

        return result;
    }


    public static <T> Result<T> failed(T data, BusinessCodeEnum businessCodeEnum) {

        Result<T> result = new Result<T>();

        result.setSuccess(false);
        result.setMessage(businessCodeEnum.getDescription());
        result.setCode(businessCodeEnum.getCode());

        result.setResult(data);

        return result;
    }

    public static <T> Result<T> failed(BusinessCodeEnum businessCodeEnum) {

        Result<T> result = new Result<T>();

        result.setSuccess(false);
        result.setMessage(businessCodeEnum.getDescription());
        result.setCode(businessCodeEnum.getCode());
        return result;
    }

    public static Result<T> success() {

        Result<T> success = new Result<>();
        success.setCode(200);
        return success;
    }


    public static Result<String> resultWithEnum(BusinessCodeEnum businessCodeEnum) {

        Result<String> failure = new Result<>();
        failure.setCode(businessCodeEnum.getCode());
        failure.setMessage(businessCodeEnum.getDescription());
        return failure;
    }

    public static Result<String> resultWithEnum(Boolean isSuccess, BusinessCodeEnum businessCodeEnum) {


        Result<String> failure = new Result<>();
        failure.setSuccess(isSuccess);
        failure.setCode(businessCodeEnum.getCode());
        failure.setMessage(businessCodeEnum.getDescription());
        return failure;
    }
}

